# -*- coding: UTF-8 -*-

from odoorpc2 import RPC
from odoorpc2.ui.action import addons_load

# addons_load('odoorpc2/addons')

addons_list = ['odoorpc2/addons']

base_url = 'http://192.168.56.111:8069'
base_url = 'http://192.168.56.114:8069'
base_url = 'http://localhost:8069'
base_url = 'http://43.143.148.83:8069'

timeout = 50000

dbname = 'baiwang_nc_base'
username = 'admin'
password = 'sdhw05363721'

rpc = RPC(base_url, timeout, dbname, addons_list)


def test_rpc():
    print('test_rpc')
    # res = rpc.version()
    res = rpc.web.webclient.version()
    print('version=', res)
    res = rpc.web.webclient.version_info()
    print('version_info=', res)
    res = rpc.web.database.list()
    print('db list=', res)

    res = rpc.web.session.authenticate(
        db=dbname, login=username, password=password)

    print('login', res)

    model = 'res.partner'
    method = 'search'

    res = rpc.web.dataset.call_kw(model, method, [])
    print('call_kw', res)
    pass


def test_rpc_call():
    print('test_rpc_call')
    res = rpc.login(username,  password)
    # res = rpc.login(username,  password)
    print('login', res)

    model = 'res.partner'
    method = 'search'
    res = rpc.call_kw(model, method, [[]], {})
    print('call_kw', res)


def test_env():
    print('test_env')
    res = rpc.env.ref('base.action_country')
    print('test_env, ref', res)

    obj = rpc.env.model('res.partner')
    res = obj.search([], order='id desc')
    print('test_env, partner', res)


def test():
    # test_rpc()
    # test_rpc_call()

    res = rpc.login(username,  password)

    # test_env()


test()
